package cn.clq.ymcc.service.impl;

import cn.clq.ymcc.domain.Login;
import cn.clq.ymcc.domain.MessageSms;
import cn.clq.ymcc.dto.CourseOnSendMessageDto;
import cn.clq.ymcc.dto.UserDto;
import cn.clq.ymcc.mapper.MessageSmsMapper;
import cn.clq.ymcc.result.JSONResult;
import cn.clq.ymcc.service.IMessageSmsService;
import cn.clq.ymcc.util.StrUtils;
import cn.clq.ymcc.util.VerifyCodeUtils;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotEmpty;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author stone.chen
 * @since 2022-07-15
 */
@Service
@Slf4j
public class MessageSmsServiceImpl extends ServiceImpl<MessageSmsMapper, MessageSms> implements IMessageSmsService {
    @Autowired
    private IMessageSmsService messageSmsService;
    /**
     * @description: 课程发布成功之后，给相关用户发送短信
     * @param: dto
     * @return: void
     * @author clqlongbao
     * @date: 2022/7/25 20:21
     */
    @Override
    public void sendMessage(CourseOnSendMessageDto dto) {
        //todo 发送短信
        log.info("短信发送成功",dto.getTitle());
        //保存短信内容到数据库
        Date date = new Date();
        dto.getUsers().forEach(user -> {
            MessageSms messageSms = new MessageSms();
            BeanUtils.copyProperties(dto,messageSms);
            messageSms.setSendTime(date);
            messageSms.setUserId(user.getId());
            messageSmsService.insert(messageSms);
        } );
    }

}
